<?php

$id = $_GET['id'];
$library = $_GET['library'];

require ("imdb.class.php");

$movie = new imdb ($HTTP_GET_VARS["mid"]);

if (isset ($HTTP_GET_VARS["mid"])) {
  $movieid = $HTTP_GET_VARS["mid"];
  $movie->setid ($movieid);

  echo "<center><b style=\"font-size: 20;\">IMDB Search</b></center>\n";
  echo "<br><br>\n";
  echo "<table width=\"100%\" border=\"1\">\n";
  echo "<tr>\n";
  echo "<td width=\"50%\"><b>Title</b></td>\n";
  echo "<td width=\"50%\">\n";
  echo $movie->title();
  echo "</td>\n";
  echo "</tr>\n";
  echo "<tr>\n";
  echo "<td width=\"50%\"><b>Genre</b></td>\n";
  echo "<td width=\"50%\">\n";
  $gen = $movie->genres ();
  for ($i = 0; $i < count ($gen); $i++) {
    echo $gen[$i];
    if ($i < (count($gen) - 1)) echo ", ";
  }
  echo "</td>\n";
  echo "</tr>\n";
  echo "<tr>\n";
  echo "<td width=\"50%\"><b>Runtime</b></td>\n";
  echo "<td width=\"50%\">\n";
  echo $movie->runtime();
  echo "min</td>\n";
  echo "</tr>\n";
  echo "<tr>\n";
  echo "<td valign=\"top\" width=\"50%\"><b>Director</b></td>\n";
  echo "<td width=\"50%\">\n";
  $directors = $movie->director();
  echo $directors[0]["name"];
  echo "</td>\n";
  echo "</tr>\n";
  echo "<tr>\n";
  echo "<td valign=\"top\" width=\"50%\"><b>Actors</b></td>\n";
  echo "<td width=\"50%\">\n";
  $cast = $movie->cast();
  if (count($cast) > 10) $cnt = 10;
  else $cnt = count($cast);
  for ($i = 0; $i < $cnt; $i++) {
    echo $cast[$i]["name"];
    if ($i < ($cnt - 1)) echo "<br>";
  }
  echo "</td>\n";
  echo "</tr>\n";
  
  echo "<tr>\n";
  echo "<td valign=\"top\" width=\"50%\"><b>Tagline</b></td>\n";
  echo "<td width=\"50%\">\n";
  echo $movie->tagline();
  echo "</td>\n";
  echo "</tr>\n";

  echo "<tr>\n";
  echo "<td valign=\"top\" width=\"50%\"><b>Plot</b></td>\n";
  echo "<td width=\"50%\">\n";
  $plot = $movie->plot();
  echo $plot[0];
  echo "</td>\n";
  echo "</tr>\n";
  
  echo "</table>\n";
  echo "<br>";
  echo "<center>\n";
  echo "<button onclick=\"location.href = 'do.php?what=updatemovie&id=$id&library=$library&imdb=1&mid=$movieid'\">Update My Movie</button>\n";
  echo "</center>\n";
}

?>
